package io.demo.message.domain.proto;

import io.demo.message.domain.AdminLevel;
import io.demo.message.domain.City;

public class CityMessageConverter implements
    MessageConverter<City, io.demo.message.domain.proto.City> {

  @Override
  public io.demo.message.domain.proto.City toMessage(City pojo) {
    Area area = MessageConverters.toMessage(pojo.getArea(), io.demo.message.domain.Area.class);
    return io.demo.message.domain.proto.City.newBuilder()
        .setId(pojo.getId())
        .setName(pojo.getName())
        .setArea(area)
        .setAdminLevel(
            io.demo.message.domain.proto.City.AdminLevel.valueOf(pojo.getAdminLevel().name()))
        .build();
  }

  @Override
  public City fromMessage(io.demo.message.domain.proto.City message) {
    io.demo.message.domain.Area area = MessageConverters
        .fromMessage(message.getArea(), io.demo.message.domain.Area.class);
    return City.builder()
        .id(message.getId())
        .name(message.getName())
        .area(area)
        .adminLevel(AdminLevel.valueOf(message.getAdminLevel().name()))
        .build();
  }
}
